from typing import List
from leetcode_test import TreeNode


class Solution:
    def rightSideView(self, root: TreeNode) -> List[int]:
        if not root:
            return []
        queue, ans = [root], [] 
        while queue:
            new_queue = []
            for node in queue:
                if node.left:
                    new_queue.append(node.left)
                if node.right:
                    new_queue.append(node.right)
            else:
                ans.append(node.val)
            queue = new_queue
        return ans


if __name__ == "__main__":
    t = TreeNode.create([1,2,3,None,5,None,4])
    print(Solution().rightSideView(t))